#include<iostream>
using namespace std;
const int N = 20;
int arr[N][N];
int n;
int main()
{
	while (cin >> n) {	
		if (n == 0) {
			break;
		}
		memset(arr, 0, sizeof(arr));
		int k = 1;
		for (int i = 1; i <= n; i++) {
			arr[1][i] = k++;
		}
		for (int i = 2; i <= n; i++) {
			arr[i][n] = k++;
		}
		for (int i = n - 1; i >= 1; i--) {
			arr[n][i] = k++;
		}
		for (int i = n - 1; i >= 2; i--) {
			arr[i][1] = k++;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (i == 1 || i == n || j == 1 || j == n) {
					printf("%3d", arr[i][j]);
				}
				else {
					printf("%3c", ' ');
				}
			}
			printf("\n");
		}
	}
	return 0;
}